package com.example.parkdemo.repair

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.blankj.utilcode.util.ToastUtils
import com.example.base.mvvm.BaseActivity
import com.example.base.net.Const
import com.example.parkdemo.R
import com.example.parkdemo.databinding.ActivityAddRepiairBinding
import com.google.gson.Gson
import dagger.hilt.android.AndroidEntryPoint
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody

@AndroidEntryPoint
class AddRepiairActivity : BaseActivity<ActivityAddRepiairBinding, RepairViewModel>() {
    override fun initData() {
        vm.getAddSuccess.observe(this) {
            ToastUtils.showLong("提交成功")
            finish()
        }
    }

    override fun initView() {
        binding.addRepairHeader.headerTitle.text = "添加维修"
        binding.addRepairHeader.headerBack.setOnClickListener { finish() }
        binding.addRepairBtn.setOnClickListener {
            val map = mutableMapOf<String, String>()
            map[Const.PARAM_REPAIR_DESCRIBE] = binding.addRepairEt.text.toString()
            map[Const.PARAM_REPAIR_TIME] = getTime()

            val json = Gson().toJson(map)
            val body = RequestBody.create(Const.MEDIA_TYPE.toMediaTypeOrNull(), json)
            vm.getAddRepair(body)
        }
    }

}